//审批提醒
$(function () {
    createHistoryTask();
});

function createHistoryTask() {
    var options = {
        url: $.webPath() + "/flow/publish/ownerHistory",
        fit: true,
        fitColumns: true,
        singleSelect: true,
        pagination: true,
        rownumbers: true
    };
    var columns = {columns: [
        [
            {field: 'executionId', title: '名称', width: 50, formatter: formatHistoryName},
            {field: 'activityName', title: '当前状态', width: 50},
            {field: 'opera', title: '提交人', width: 50},
            {field: 'time', title: '时间', width: 50}
        ]
    ]}
    options = $.extend(options, columns);
    $('#lsrw-grid').datagrid(options);
}


function formatHistoryName(val, row) {
    var type = val.substring(0, val.indexOf('.'));
    return '<a href="javascript:viewHistoryDetail(\'' + val + '\',\'' + type + '\');" style="color: red">' + type + '</a>';
}

function viewHistoryDetail(executionId, type) {
    if (type == '协议流程') {
        $.post($.webPath() + "/jhgl/xygl/xyglByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jhgl/xygl/xygl_detail?type=" + obj.type + "&xyId=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '采购合同流程') {
        $.post($.webPath() + "/htgl/cghtgl/cghtByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/htgl/cghtgl/cghtgl_detail?type=" + obj.type + "&cghtId=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '销售合同流程') {
        $.post($.webPath() + "/htgl/xshtgl/xshtByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/htgl/xshtgl/xshtgl_detail?type=" + obj.type + "&xshtId=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '自购物资计划流程') {
        $.post($.webPath() + "/jhgl/wzjhgl/wzjhByProcessInstance", {'executionId': executionId, 'type': 'Zgwzjh'}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jhgl/wzjhgl/wzjhgl_detail?type=" + obj.type + "&id=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '自购资金计划流程') {
        $.post($.webPath() + "/jhgl/zjjhgl/zjjhByProcessInstance", {'executionId': executionId, 'type': 'Zgzjjh'}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jhgl/zjjhgl/zjjhgl_detail?type=" + obj.type + "&id=" + obj.id + "&jhsp=true";
            popHistoryWindow(href, type);
        });
    } else if (type == '统配物资计划流程') {
        $.post($.webPath() + "/jhgl/wzjhgl/wzjhByProcessInstance", {'executionId': executionId, 'type': 'Tpwzjh'}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jhgl/wzjhgl/wzjhgl_detail?type=" + obj.type + "&id=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '统配资金计划流程') {
        $.post($.webPath() + "/jhgl/zjjhgl/zjjhByProcessInstance", {'executionId': executionId, 'type': 'Tpzjjh'}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jhgl/zjjhgl/zjjhgl_detail?type=" + obj.type + "&id=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '电子借款单流程') {
        $.post($.webPath() + "/jhgl/jkd/jkdByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jhgl/jkd/jkd_detail?type=" + obj.type + "&jkdId=" + obj.id ;
            popHistoryWindow(href, type);
        });
    } else if (type == '路径流程') {
        $.post($.webPath() + "/organ/ljwh/ljByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/organ/ljwh/ljwh_detail?type=" + obj.type + "&ljId=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '企业机构流程') {
        $.post($.webPath() + "/organ/qyjg/qyjgByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/organ/qyjg/qyjg_detail?operation=update&qyjgId=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '供应商流程') {
        $.post($.webPath() + "/organ/gys/ljLsByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/organ/gys/gys_detail?operation=update&ljLsId=" + obj.id;
            popHistoryWindow(href, type);
        });
    } else if (type == '付款流程') {
        $.post($.webPath() + "/sfgl/fksh/fkshByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/sfgl/fksh/fksh_detail?fkshId=" + obj.id;
            popHistoryWindow(href, type);
        });
    }else if (type == '特批付款流程') {
        $.post($.webPath() + "/sfgl/tpfk/tpfkshByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/sfgl/tpfk/tpfk_detail?tpfkId=" + obj.id;
            popHistoryWindow(href, type);
        });
    }else if (type == '资金补差单流程') {
        $.post($.webPath() + "/jsgl/zjbcd/zjbcdByProcessInstance", {'executionId': executionId}, function (data) {
            var obj = eval('(' + data + ')');
            var href = $.webPath() + "/jsgl/zjbcd/zjbcd_detail?tpfkId=" + obj.id;
            popHistoryWindow(href, type);
        });
    }

}

function popHistoryWindow(href, type) {
    var detailHiswin = $.window({
        iconCls: 'icon-add2',
        title: type,
        url: href,
        width: 1024,
        height: 500,
        modal: true,
        isMax: false,
        buttons: []
    });
}
